<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\VipController\doRule;
use App\Services\Admin\Store;
use App\Services\Admin\Vip;
use Illuminate\Http\Request;

class VipController extends Controller
{
    public function index()
    {
        $vip_result = Vip::lists()->paginate(15);

        $result = [
            'result'=>$vip_result,
            'sear_value'=>\request()->get('sear_value'),
        ];

        return view('admin.vip.index', $result);
    }

    public function add()
    {
        $result = [
            'select_store' => Store::where_lists(),
            'store_id' => \request()->get('store_id'),
            'class_base_info' => Vip::class_base_info()
        ];

        return view('admin.vip.edit', $result);
    }

    public function edit(Request $request, $id)
    {
        $result = [
            'select_store' => Store::where_lists(),
            'store_id' => \request()->get('store_id'),
            'class_base_info' => Vip::class_base_info(),
            'info' => Vip::info($id),
            'id' => $id
        ];

        return view( 'admin.vip.edit', $result);
    }

    public function do(doRule $request)
    {
        if ($request->ajax()) {

            $input = $request->all();

            if (empty($input['id'])) {

                unset($input['id']);

                $group_result = Vip::add($input);

            }else{

                $group_result = Vip::edit($input['id'], $input);

            }

            if(!$group_result['bool'])return self::fail($group_result['message']);

            return self::success([]);
        }
    }

    public function del($id)
    {
        Vip::del($id);

        return self::success([]);
    }

    public function search()
    {
        return self::success(Vip::class_base_info());
    }
}
